<template>
  <div class="main-box">
    <div class="blog-config" @click="toOther()">
      <a-icon
        :class="{ 'smile-btn': true, 'smile-color': isPortal }"
        type="smile"
        theme="outlined"
      />
    </div>
    <div class="tob-bar">
      <span>some time life is hard , but everyting will pass.</span>
    </div>
    <div class="blog-main">
      <div class="blog-left">
        <NavBar @fun="changeComponent"></NavBar>
      </div>
      <div class="blog-right">
        <!-- 刷新不会进行重置 -->
        <router-view ref="childCom"></router-view>
        <!-- 动态组件刷新会重置为初始的状态 -->
        <!-- <component v-if="isNav" :is="componentName"></component>
        <component :blog="blog" v-else :is="componentConent"></component> -->
      </div>
    </div>
    <div>
      <a-back-top />
    </div>
  </div>
</template>
<script>
import NavBar from '../components/NavBar'

export default {
  name: 'home',
  components: {
    NavBar,
  },
  data() {
    return {
      avatarUrl: '',
      name: '',
      componentName: 'BlogTitle',
      componentConent: 'BlogContent',
      isNav: true,
      blog: {}, // 当前bolg 的id
      isPortal: false,
    }
  },
  created() {},
  methods: {
    changeComponent(data) {
      this.isNav = true
      this.componentName = data
    },
    showBlogContent(id) {
      this.$axios.post('/getBlogInfo', { id: id }).then((data) => {
        if (data.status === 200) {
          this.isNav = false
          this.blog = data.data
        }
      })
    },
    // 其他配置
    toOther() {
      this.isPortal = !this.isPortal
      if(window.localStorage.getItem('userId')){
         this.$router.push({
          path: '/home',
        })
      }else{
         this.$router.push('/login')
      }
      // 已经登录的情况
      // if (true) {
      //   this.$router.push({
      //     path: '/home',
      //   })
      // } else {
      //   // 如果没有进行登录就跳转到登录页面
      //   this.$router.push('/login')
      // }
    },
  },
}
</script>

<style lang="less" scoped>
.main-box {
  .blog-config {
    cursor: pointer;
    position: absolute;
    left: 20px;
    top: 20px;
  }
  .smile-btn {
    font-size: 30px;
  }
  .smile-color {
    color: #1890ff;
  }
  .tob-bar {
    height: 100px;
    text-align: center;
    padding-top: 40px;
    font-size: 16px;
    animation: 1.5s hd linear;
  }
  .blog-main {
    width: 1200px;
    min-width: 680px;
    display: flex;
    flex-direction: row;
    margin: 0 auto;
  }
  .blog-left {
    width: 30%;
  }
  .blog-right {
    width: 70%;
  }
}

@keyframes hd {
  0% {
    padding-top: 0px;
  }
  100% {
    padding-top: 40px;
  }
}
</style>
